package 多线程.复习.线程方法;

public class WaitState {
    public static void main(String[] args) {
        Object lock = new Object();
        Thread t1 = new Thread(() ->{
            synchronized (lock){
                while (true){
                    try {
//                        Thread.sleep(1000);//调用此方法，线程1处在超时等待状态：timed-waiting
                        lock.wait();//调用wait，线程1进入wait状态，等待其他线程唤醒
                        System.out.println("我被t2唤醒了一次");
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        },"t1");
        Thread t2 = new Thread(() ->{
            synchronized (lock){
                System.out.println("她");
                lock.notify();
            }
        },"t2");
        t1.start();
        t2.start();
    }
}
